<?php
// 应用公共文件

///接口返回
function AjaxReturn($code,$msg,$data = null,$count = 0){
    $res = [
        'code'=>$code,
        'msg' =>$msg,
        'data'=>$data,
        'count'=>$count
    ];
    return $res;
}


 function isEmpty($obj){
    if($obj == null || $obj == '' || $obj == 'null' || $obj == 'NULL' || $obj == 'undefined' || $obj == 'Undefined'){
        return true;
    }else{
        return false;
    }
}

function getTree($items){
    $tree = [];

    $items_index = [];

    foreach($items as $v){
        $v = (array)$v;
        $v['title'] = $v['router_name'];
        $items_index[$v['id']] = $v;
    }

    foreach($items_index as $v){
        if(isset($items_index[$v['parent_id']])){
            $items_index[$v['parent_id']]['children'][] = &$items_index[$v['id']];
        }else{
            $tree[] = &$items_index[$v['id']];
        }
    }
    return $tree;
}